from db import db1
class ACL:
    def __init__(self):
        ...
    # 给用户添加资源
    def set_resource(self,uid,reslist):
        for i in reslist:
            sql="insert into user_resource(userid,resourceid) values(%d,%d)"%(int(uid),int(i))
            db1.update(sql)
    # 修改权限
    def update_resource(self,uid,reslist):
        # 先删除原来在添加
        sql="delete from user_resource where userid=%d"%(int(uid))
        db1.update(sql)
        self.set_resource(uid,reslist)

    # 删除某个权限
    def delete_resource(self,uid,resourceid):
        sql="delete from user_resource where userid=%d and resourceid=%d"%(int(uid),int(resourceid))
        db1.update(sql)
    # 获取页面资源列表
    def get_page_relist(self,uid):
        # type 1 为前端  2 为后端
        sql="select r.url as url from user_resource as u innor join resource as r on u.resourceid=r.id where u.userid=%d and r.type=1"%(int(uid))
        res=db1.find_all(sql)
        list=[]
        for i in res:
            list.append(i['url'])
        return list
    # 获取接口资源列表
    def get_interface_relist(self,uid):
        sql = "select r.url as url from user_resource as u innor join resource as r on u.resourceid=r.id where u.userid=%d and r.type=2" % (int(uid))
        res=db1.find_all(sql)
        list=[]
        for i in res:
            list.append(i['url'])
        return list
acl=ACL()








